package com.mall.market.controller;


import com.mall.commons.utils.CommonResult;
import com.mall.market.service.SmsFlashPromotionService;
import com.mall.model.domain.SmsFlashPromotion;
import com.mall.model.vo.CommonPage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/flash")
public class SmsFlashPromotionController {


    @Autowired
    private SmsFlashPromotionService smsFlashPromotionService;

    /**
     * 根据活动名称分页查询
     */
    @GetMapping("/list")
    public CommonResult flashPromotion(String keyword, Integer pageNum,
                                       Integer pageSize) {

        CommonPage pageResult = smsFlashPromotionService.FlashPromotionList(keyword, pageNum, pageSize);
        return CommonResult.success(pageResult);
    }

    /**
     * 添加活动
     * @param smsFlashPromotion
     * @return
     */
    @PostMapping("/create")
    public CommonResult addFlashPromotion(@RequestBody SmsFlashPromotion smsFlashPromotion) {
        smsFlashPromotionService.addFlashPromotion(smsFlashPromotion);
        return CommonResult.success("添加成功");
    }

    /**
     * 根据id删除活动
     * @param id
     * @return
     */
    @PostMapping("/delete/{id}")
    public CommonResult deleteFlashPromotion(@PathVariable("id") Integer id){
        smsFlashPromotionService.deleteFlashPromotion(id);
        return CommonResult.success("删除成功");
    }

    /**
     * 修改上下线状态
     * @return
     */
    @PostMapping("/update/status/{id}")
    public CommonResult updateStatus(@PathVariable("id") Integer id,Integer status){
        smsFlashPromotionService.updateStatus(id,status);
        return CommonResult.success("修改成功");
    }

    /**
     * 获取活动详情
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public CommonResult selectFlashPromotion(@PathVariable("id") Integer id){
        SmsFlashPromotion flashPromotion = smsFlashPromotionService.selectFlashPromotion(id);
        return CommonResult.success(flashPromotion);
    }

    /**
     *
     * @param id
     * @param smsFlashPromotion
     * @return
     */
    @PostMapping("/update/{id}")
    public CommonResult updateFlashPromotion(@PathVariable("id") Integer id,@RequestBody SmsFlashPromotion smsFlashPromotion){
        smsFlashPromotionService.updateFlashPromotion(id,smsFlashPromotion);
        return CommonResult.success("修改成功");
    }
}
